package com.ray.test.hander;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;

import java.util.ArrayList;
import java.util.List;

/**
 * @author bo shen
 * @Description: 上下文容器
 * @Class: HanderContent
 * @Package com.ray.test.hander
 * @date 2019/12/12 15:18
 * @company <p>杭州传化陆鲸科技有限公司</p>
 * @updateRecord time(修改时间)  author(修改人)   desc(修改内容)
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Slf4j
public class HanderContent {
    /***需要执行的方法***/
    private List<String> includeMethodName = new ArrayList<>();
    /***需要排除的方法***/
    private List<String> excludeMethodName = new ArrayList<>();
    /**容器上下文***/
    private ApplicationContext applicationContext;
    /***事务管理器**/
    private PlatformTransactionManager platformTransactionManager;
    private TransactionDefinition transactionDefinition;
    /***需要执行的类列表**/
    private List<Class<?>> runClasss;

    /***开启事务**/
    public TransactionStatus open() {
        TransactionStatus transaction = null;
        if (platformTransactionManager != null && transactionDefinition != null) {
            transaction =platformTransactionManager.getTransaction(transactionDefinition);
        }
        return transaction;
    }

   /***事务回滚***/
    public void rollback(TransactionStatus transactionStatus) {
        if (platformTransactionManager != null && transactionDefinition != null) {
            platformTransactionManager.rollback(transactionStatus);
        }
    }
}
